package study.web;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

public class AbstractPlainController {

	/**
	 * 단순 컨텐츠를 출력한다.
	 */
	@RequestMapping(value="/**", method=RequestMethod.GET)
	public String plain(HttpServletRequest request, HttpServletResponse response)
		throws IOException
	{
		String ctxRoot = request.getContextPath();
		String uri = request.getRequestURI();
		int len = 0;
		if(ctxRoot != null && ctxRoot.length() > 0) {
			len = uri.indexOf(ctxRoot) + ctxRoot.length();
		}
		uri = uri.substring(len);
		if(uri.split("/").length < 2) {
			response.sendError(HttpServletResponse.SC_NOT_FOUND);
			return null;
		}
		return uri.substring(1);
	}
}
